Skip to content

fix: PG packet monitor names and key mismatch flag not clearing#2406

Merged
Yeraze merged 1 commit intomainfrom
fix/pg-packet-names-and-key-clear
Mar 23, 2026
Merged

fix: PG packet monitor names and key mismatch flag not clearing#2406
Yeraze merged 1 commit intomainfrom
fix/pg-packet-names-and-key-clear

Conversation

@Yeraze
Copy link
Copy Markdown
Owner

@Yeraze Yeraze commented Mar 23, 2026

Summary

Two bugs affecting PostgreSQL (and key clearing on all backends):

1. Packet Monitor showing hex IDs instead of node names on PostgreSQL

  • Root cause: PostgreSQL lowercases unquoted column aliases. SELECT ... as from_node_longName returns from_node_longname in PG results, but frontend expects from_node_longName.
  • Fix: normalizePacketLogRow now checks both cases: row.from_node_longName ?? row.from_node_longname

2. Key mismatch warning never clearing

  • Root cause: Code set nodeData.keySecurityIssueDetails = undefined to clear the field, but the upsert used ?? (nullish coalescing) which treats undefined as "not provided" and falls back to the existing DB value — so the warning persisted forever.
  • Fix: Changed clear assignments to null, and updated upsert to use !== undefined checks so null explicitly clears the field.

Changes

File Change
src/db/repositories/misc.ts Normalize PG lowercase aliases in normalizePacketLogRow
src/db/repositories/nodes.ts Use !== undefined for security flag fields in upsert
src/server/meshtasticManager.ts Use null instead of undefined to clear security fields
src/server/routes/securityRoutes.ts Same null fix for manual security flag clear

Test plan

  • npx vitest run — 3070 tests pass
  • npm run build — no TypeScript errors
  • Verify packet monitor shows node names on PostgreSQL
  • Verify key mismatch warning clears after NodeInfo exchange on PostgreSQL

🤖 Generated with Claude Code

Two PostgreSQL-specific bugs:

1. Packet Monitor showing hex IDs instead of node names on PG:
   PostgreSQL lowercases unquoted column aliases, so `from_node_longName`
   became `from_node_longname` in results. Added normalization in
   normalizePacketLogRow to handle both cases.

2. Key mismatch warning never clearing on any backend:
   Setting `nodeData.keySecurityIssueDetails = undefined` to clear it
   was ineffective because the upsert used `??` which treats undefined
   as "not provided" and falls back to the existing value. Changed to
   `null` and updated upsert to use `!== undefined` checks so null
   explicitly clears the field.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 23, 2026

Claude finished @Yeraze's task —— View job


PR Code Review

Reviewing this pull request for code quality, potential bugs, performance considerations, security concerns, and test coverage.

Todo List:

  • Read repository guidelines (CLAUDE.md)
  • Analyze database repository changes (misc.ts)
  • Analyze nodes repository changes (nodes.ts)
  • Analyze meshtastic manager changes
  • Analyze security routes changes
  • Evaluate PostgreSQL column alias fix
  • Evaluate null vs undefined key clearing fix
  • Check for potential bugs and edge cases
  • Assess performance implications
  • Review security considerations
  • Evaluate test coverage needs
  • Provide final review summary

Review Findings

Overall Assessment: APPROVED

Both fixes are well-implemented and address real issues with clear root cause analysis. The changes are minimal, focused, and follow project conventions.


🔧 Bug Fix 1: PostgreSQL Packet Monitor Names

Problem: PostgreSQL lowercases unquoted column aliases, causing from_node_longName to become from_node_longname in results, breaking the frontend display.

Fix: Added fallback logic in normalizePacketLogRow() (misc.ts:842-843):

from_node_longName: row.from_node_longName ?? row.from_node_longname ?? null,
to_node_longName: row.to_node_longName ?? row.to_node_longname ?? null,

✅ Quality: Excellent defensive programming - handles both camelCase and lowercase variants without breaking other databases.


🔧 Bug Fix 2: Key Mismatch Warnings Never Clearing

Problem: Code set keySecurityIssueDetails = undefined to clear the field, but the upsert used ?? (nullish coalescing), treating undefined as "not provided" and falling back to existing DB value.

Root Cause: undefined vs null semantic difference in database operations.

Fix:

  1. Changed clearing assignments from undefined to null (meshtasticManager.ts, securityRoutes.ts)
  2. Updated upsert logic from ?? to !== undefined checks (nodes.ts:167-170)

✅ Quality:

  • Proper fix that maintains backward compatibility
  • Consistent approach across all security flags
  • Clear comments explaining the difference

📊 Code Quality Assessment

Strengths:

  • Minimal, surgical changes - only touches affected code paths
  • Database-agnostic approach - works across SQLite/PostgreSQL/MySQL
  • Clear comments explaining PostgreSQL-specific behavior
  • Consistent patterns - applies same fix to all related security fields
  • Good error handling - maintains existing error boundaries

Performance Considerations:

  • Zero performance impact - changes are in normalization/assignment logic
  • No additional database queries - pure data transformation
  • Fallback logic is efficient - uses nullish coalescing operator

Security Considerations:

  • No security implications - purely data handling fixes
  • Maintains data integrity - doesn't alter validation logic
  • Preserves access controls - no changes to authentication/authorization

Test Coverage:

  • Author reports 3070 tests pass - good coverage validation
  • Changes are in data layer - existing packet log tests should catch regressions
  • Manual test plan provided for verification

🎯 Specific Technical Notes

PostgreSQL Column Aliasing:

The PostgreSQL behavior is standard SQL - unquoted identifiers are lowercased. This fix is more robust than quoting aliases because it maintains compatibility with existing queries.

Null vs Undefined Semantics:

The distinction is crucial in JavaScript/TypeScript database operations:

  • undefined = "field not provided, preserve existing value"
  • null = "explicitly set field to null"

Database Architecture Compliance:

Changes follow the repository's multi-database architecture patterns correctly, using the base repository's normalization methods.


📝 Minor Suggestions

  1. Consider adding a unit test for the PostgreSQL column alias normalization to prevent regression
  2. Documentation: The comment about PostgreSQL behavior is helpful - consider adding similar context to the git commit for future reference

Recommendation: APPROVE AND MERGE

This PR addresses two legitimate bugs with clean, targeted fixes. The code follows project conventions, maintains backward compatibility, and includes proper testing validation. No blocking issues found.

@Yeraze Yeraze merged commit 3526e82 into main Mar 23, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant